﻿@{
    ViewBag.Title = "Index";
    ViewBag.First = "消息推送";
    Layout = "~/Views/Shared/_BaseLayout.cshtml";
    var list = ViewData["type"] as IList<Sc.Domain.BaseItem>;
}
<script type="text/javascript">
    $(document).ready(function (e) {
   
    });
    //司机选择
    function selectDriver() {
        layer.open({
            type: 2,
            title: "接受消息人员选择",
            shade: [0],
            area: [($(window).width() - 20) + "px", ($(window).height() - 80) + "px"],
            content: ['@Url.Action("SelectUser", "CarInfo")', 'false']
        });
    }
    //司机选择后
    function sureDriver(list) {
        var table = document.getElementById("listData");
        for (var i = 0; i < list.length; i++) {
            var row = table.insertRow(table.rows.length);
            var index = row.insertCell(0);
            index.innerHTML = (i + 1).toString();
            var name = row.insertCell(1);
            name.innerHTML = list[i].Name + "<input type='hidden' tag='" + list[i].Id + "' />";
            var opa = row.insertCell(2);
            opa.innerHTML = '<a href="javascript:void(0)" onclick="del(this);" class="tablelink">删除</a>';
        }
        layer.closeAll();
    }
    
    //删除
    function del(obj) {
        layer.confirm("您确定要删除吗？", function () {
            $(obj).parent().parent().remove();
            layer.closeAll();
        });
    }
    //数据保存
    function saveData() {
        var txtremark = $("#txtremark").val();
        var list = $("#listData tr").find("input[type=hidden]");
        if (txtremark.length <= 0) {
            Tips("请输入发送内容", "txtremark");
            return false;
        }
        if (list.length <= 0) {
            loadTip("请至少选择一个用户", 2, 1000);
            return false;
        }
        var arr = new Array();
        for (var i = 0; i < list.length; i++) {
            var ent = new Object();
            ent.UserId = $(list[i]).attr("tag");
            arr.push(ent);
        }
        var url = "@Url.Action("SaveData")";
        var load = loadTip("数据提交中，请稍后", 16, 0);
        $.post(url, { txtremark: txtremark, data: JSON.stringify(arr) }, function (data) {
            if (data > 0) {
                layer.msg("数据保存成功", { icon: 1, time: 1000, shade: [0.3, '#000'] }, function () { back()});
            } else {
                loadTip("数据保存失败", 2, 1000);
            }
        });
    }
    function back() {
        window.location.href = "@Url.Action("index")";
    }
</script>
<div class="formbody">
    <div class="formtitle"><span>消息推送</span></div>
    <div class="tools">
        <ul class="seachform">
            <li>
                <label>消息内容</label>
                <textarea id="txtremark" class="dfinput" cols="3" style="width:380px; height:50px;"></textarea>
            </li>
            <li>
                <label>&nbsp;</label>
                <input type="button" class="scbtn" style="width:160px;" onclick="selectDriver();" value="选择消息接受人员" />
                <input type="button" class="scbtn" onclick="saveData();" value="发 送" />
                <input type="button" class="scbtn" onclick="back();;" value="返 回" />
            </li>
        </ul>
    </div>
    <table class="tablelist">
        <thead>
            <tr>
                <th width="60">编号</th>
                <th>姓名</th>
                <th width="60">操作</th>
            </tr>
        </thead>
        <tbody id="listData"></tbody>
    </table>
</div>